package batch;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import classifier.Classifier;
import classifier.ClassifierFactory;
import dao.FileIO;

public class BatchClassifier {

	public void proceed(String [] args) {
		String classifierType = args[0];
		String testFileList = args[1];
		
		Classifier classifier = ClassifierFactory.getClassifier(classifierType);
		
		List<String> sub = new ArrayList<String>(args.length - 2);
		for(int i = 2; i < args.length; i++) {
			sub.add(args[i]);
		}
		List<String> lines = FileIO.readFile(testFileList);
		Iterator<String> itr = lines.iterator();
		String trainFile = itr.next();
		
		classifier.train(trainFile, sub);
		
		while(itr.hasNext()) {
			String line = itr.next();
			String [] tokens = line.split(" ");
			String testFile = tokens[0];
			String resultFile = tokens[1];
			
			System.out.println("classifing " + testFile);
			classifier.test(testFile, resultFile);
		}
	}
	
	public static void main(String[] args) {
		BatchClassifier m = new BatchClassifier();
		m.proceed(args);
	}

}
